<template>
  <div>
    <Chart :cdata="cdata" />
  </div>
</template>

<script>
import Chart from './chart.vue'
import {yieldDataDay, yieldData} from '@/api/yield'
import dayjs from 'dayjs'
import customParseFormat from 'dayjs/plugin/customParseFormat'
dayjs.extend(customParseFormat)

export default {
  components: {
    Chart
  },
  data() {
    return {
      yieldAllLineData: {
        'code': 200,
        'msg': null,
        'data': [
          {
            'createBy': null,
            'createTime': null,
            'updateBy': null,
            'updateTime': null,
            'remark': null,
            'staticId': 'c*1*2025-05-20',
            'classes': 'c',
            'line': '1',
            'reportTime': null,
            'beginTime': '2025-05-20 00:00:00',
            'endTime': '2025-05-20 14:41:00',
            'woolenBoardWidth': 3562,
            'pullSpeed': null,
            'dailyOutput': 20445.000528000000,
            'qualifiedBoardSquare': 18688.7008,
            'qualifiedBoardWeight': null,
            'qualifiedBoardPieces': 7273,
            'qualifiedBoardAccout': 0.914,
            'waste': 768.3104,
            'wasteAccout': 0.038,
            'sq4Accout': 0.000,
            'sq3Accout': 0.000,
            'sq2Accout': 0.011,
            'sq1Accout': 0.903,
            'samplingSquare': 0.0000,
            'samplingWeight': null,
            'samplingAccout': 0.000,
            'clearLossesSquare': 987.989328000000,
            'clearLossesWeight': null,
            'clearLossesAccout': 0.048,
            'redBoardSquare': 729.7664,
            'redBoardWeight': null,
            'redBoardAccout': 0.036,
            'manualSquare': 7.7088,
            'manualWeight': null,
            'manualAccout': 0.000,
            'downstreamSquare': 0.0000,
            'downstreamWeight': null,
            'downstreamAccout': 0.000,
            'bz1': null,
            'bz2': null,
            'bz3': null,
            'bz4': null,
            'bz5': null,
            'sq2': 223.5552,
            'sq4': 0.0000,
            'sq1': 18465.1456,
            'sq3': 0.0000
          },
          {
            'createBy': null,
            'createTime': null,
            'updateBy': null,
            'updateTime': null,
            'remark': null,
            'staticId': 'c*2*2025-05-20',
            'classes': 'c',
            'line': '2',
            'reportTime': null,
            'beginTime': '2025-05-20 00:00:00',
            'endTime': '2025-05-20 14:41:00',
            'woolenBoardWidth': 3619,
            'pullSpeed': null,
            'dailyOutput': 20103.517644000000,
            'qualifiedBoardSquare': 18309.8994,
            'qualifiedBoardWeight': null,
            'qualifiedBoardPieces': 6814,
            'qualifiedBoardAccout': 0.911,
            'waste': 489.0522,
            'wasteAccout': 0.024,
            'sq4Accout': 0.000,
            'sq3Accout': 0.000,
            'sq2Accout': 0.010,
            'sq1Accout': 0.901,
            'samplingSquare': 0.0000,
            'samplingWeight': null,
            'samplingAccout': 0.000,
            'clearLossesSquare': 1304.566044000000,
            'clearLossesWeight': null,
            'clearLossesAccout': 0.065,
            'redBoardSquare': 462.1812,
            'redBoardWeight': null,
            'redBoardAccout': 0.023,
            'manualSquare': 8.0613,
            'manualWeight': null,
            'manualAccout': 0.000,
            'downstreamSquare': 0.0000,
            'downstreamWeight': null,
            'downstreamAccout': 0.000,
            'bz1': null,
            'bz2': null,
            'bz3': null,
            'bz4': null,
            'bz5': null,
            'sq2': 193.4712,
            'sq4': 0.0000,
            'sq1': 18116.4282,
            'sq3': 0.0000
          },
          {
            'createBy': null,
            'createTime': null,
            'updateBy': null,
            'updateTime': null,
            'remark': null,
            'staticId': 'c*3*2025-05-20',
            'classes': 'c',
            'line': '3',
            'reportTime': null,
            'beginTime': '2025-05-20 00:00:00',
            'endTime': '2025-05-20 14:41:00',
            'woolenBoardWidth': 3495,
            'pullSpeed': null,
            'dailyOutput': 19050.802830000000,
            'qualifiedBoardSquare': 18051.4400,
            'qualifiedBoardWeight': null,
            'qualifiedBoardPieces': 7025,
            'qualifiedBoardAccout': 0.948,
            'waste': 426.5536,
            'wasteAccout': 0.022,
            'sq4Accout': 0.000,
            'sq3Accout': 0.000,
            'sq2Accout': 0.002,
            'sq1Accout': 0.946,
            'samplingSquare': 0.0000,
            'samplingWeight': null,
            'samplingAccout': 0.000,
            'clearLossesSquare': 572.809230000000,
            'clearLossesWeight': null,
            'clearLossesAccout': 0.030,
            'redBoardSquare': 413.7056,
            'redBoardWeight': null,
            'redBoardAccout': 0.022,
            'manualSquare': 0.0000,
            'manualWeight': null,
            'manualAccout': 0.000,
            'downstreamSquare': 0.0000,
            'downstreamWeight': null,
            'downstreamAccout': 0.000,
            'bz1': null,
            'bz2': null,
            'bz3': null,
            'bz4': null,
            'bz5': null,
            'sq2': 38.5440,
            'sq4': 0.0000,
            'sq1': 18012.8960,
            'sq3': 0.0000
          },
          {
            'createBy': null,
            'createTime': null,
            'updateBy': null,
            'updateTime': null,
            'remark': null,
            'staticId': 'c*4*2025-05-20',
            'classes': 'c',
            'line': '4',
            'reportTime': null,
            'beginTime': '2025-05-20 00:00:00',
            'endTime': '2025-05-20 14:41:00',
            'woolenBoardWidth': 3624,
            'pullSpeed': null,
            'dailyOutput': 19555.984720000000,
            'qualifiedBoardSquare': 17604.3296,
            'qualifiedBoardWeight': null,
            'qualifiedBoardPieces': 6851,
            'qualifiedBoardAccout': 0.900,
            'waste': 691.2224,
            'wasteAccout': 0.035,
            'sq4Accout': 0.000,
            'sq3Accout': 0.000,
            'sq2Accout': 0.015,
            'sq1Accout': 0.885,
            'samplingSquare': 0.0000,
            'samplingWeight': null,
            'samplingAccout': 0.000,
            'clearLossesSquare': 1260.432720000000,
            'clearLossesWeight': null,
            'clearLossesAccout': 0.064,
            'redBoardSquare': 686.0832,
            'redBoardWeight': null,
            'redBoardAccout': 0.035,
            'manualSquare': 0.0000,
            'manualWeight': null,
            'manualAccout': 0.000,
            'downstreamSquare': 0.0000,
            'downstreamWeight': null,
            'downstreamAccout': 0.000,
            'bz1': null,
            'bz2': null,
            'bz3': null,
            'bz4': null,
            'bz5': null,
            'sq2': 292.9344,
            'sq4': 0.0000,
            'sq1': 17311.3952,
            'sq3': 0.0000
          },
          {
            'createBy': null,
            'createTime': null,
            'updateBy': null,
            'updateTime': null,
            'remark': null,
            'staticId': 'c*5*2025-05-20',
            'classes': 'c',
            'line': '5',
            'reportTime': null,
            'beginTime': '2025-05-20 00:00:00',
            'endTime': '2025-05-20 14:41:00',
            'woolenBoardWidth': 3569,
            'pullSpeed': null,
            'dailyOutput': 19050.053116000000,
            'qualifiedBoardSquare': 17157.2192,
            'qualifiedBoardWeight': null,
            'qualifiedBoardPieces': 6677,
            'qualifiedBoardAccout': 0.901,
            'waste': 937.9040,
            'wasteAccout': 0.049,
            'sq4Accout': 0.000,
            'sq3Accout': 0.000,
            'sq2Accout': 0.010,
            'sq1Accout': 0.891,
            'samplingSquare': 0.0000,
            'samplingWeight': null,
            'samplingAccout': 0.000,
            'clearLossesSquare': 954.929916000000,
            'clearLossesWeight': null,
            'clearLossesAccout': 0.050,
            'redBoardSquare': 745.1840,
            'redBoardWeight': null,
            'redBoardAccout': 0.039,
            'manualSquare': 51.3920,
            'manualWeight': null,
            'manualAccout': 0.003,
            'downstreamSquare': 0.0000,
            'downstreamWeight': null,
            'downstreamAccout': 0.000,
            'bz1': null,
            'bz2': null,
            'bz3': null,
            'bz4': null,
            'bz5': null,
            'sq2': 192.7200,
            'sq4': 0.0000,
            'sq1': 16964.4992,
            'sq3': 0.0000
          }
        ]
      },
      cdata: {
        dataList: [
          '05-21 1线',
          '05-21 2线',
          '05-21 3线',
          '05-21 4线',
          '05-21 5线'
        ],
        dayList: [25516, 25457, 22787, 24886, 24108],
        nightList: [26567, 26000, 25884, 24978, 25138]
      }
    }
  },
  mounted() {
    // this.setData()
    this.getLastClassReport()
    this.timeFn2()
  },
  beforeDestroy() {
    clearInterval(this.timing2)
  },
  methods: {
    getLastClassReport() {
      const current = new Date()
      this.queryParams = { params: { beginTime: '', endTime: ''} }
      // {"params":{"beginTime":"2025-05-20 00:00:00","endTime":"2025-05-25 23:59:59","sort":"DESC"}}
      this.queryParams.params.beginTime = dayjs(current).subtract(1, 'day').format('YYYY-MM-DD') + ' 08:00:00'
      this.queryParams.params.endTime = dayjs(current).format('YYYY-MM-DD') + ' 07:59:59'
      // this.queryParams.params.beginTime = '2025-05-21 08:00:00' // 测试服数据 todo 生产端该行需要注释
      // this.queryParams.params.endTime = '2025-05-22 07:59:59' // 测试服数据 todo 生产端该行需要注释
      const queryDate = this.queryParams.params.beginTime.substring(5, 10)
      yieldData(this.addParam(this.queryParams, 'sort', 'DESC')).then(response => {
        // 分五线 只查1天
        const dataList = [queryDate + ' 1线', queryDate + ' 2线', queryDate + ' 3线', queryDate + ' 4线', queryDate + ' 5线']
        // const currentYieldDay = response.data // todo 考虑排序 使用主键排序 staticId b*5*2025-05-21
        const dayList = [0, 0, 0, 0, 0]
        const nightList = [0, 0, 0, 0, 0]
        const AllList = response.data.reduce((acc, cur) => {
          const lineNum = Number(cur.staticId.substring(2, 3))
          if (cur.staticId.substring(0, 1) === 'a') {
            // 白班
            dayList[lineNum - 1] = cur.qualifiedBoardSquare
          } else if (cur.staticId.substring(0, 1) === 'b') {
            // 晚班
            nightList[lineNum - 1] = cur.qualifiedBoardSquare
          }
          return acc
        }, [])
        console.log('dataList', dataList)
        console.log('dayList', dayList)
        console.log('nightList', nightList)
        this.cdata = {
          dataList: dataList,
          dayList: dayList,
          nightList: nightList
        }
      })
    },
    // 请求产量 按返回值处理cdata
    setData() {
      const dataList = ['05-21 1线', '05-21 2线', '05-21 3线', '05-21 4线', '05-21 5线']
      const dayList = [25516, 25457, 22787, 24886, 24108]
      const nightList = [26567, 26000, 25884, 24978, 25138]
      // for (let i = 0; i < 5; i++) {
      //   const res = yieldList[i] - nightList[i]
      //   dayList.push(res)
      // }
      // console.log('dayList', dayList)
      // 五线班报数据 白晚班
      // yieldData
    },
    // 循环请求
    timeFn2() {
      this.timing2 = setInterval(() => {
        console.log('昨日班报 right 实时', dayjs(new Date()).format('YYYYMMDDHHmmss'))
        // this.setData()
        this.getLastClassReport()
        // todo last6min 刷新间隔
      }, 1800000)
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
